package com.zl.learning.xml;

import com.google.gson.Gson;
import com.zl.learning.xml.pojo.Dic;
import com.zl.learning.xml.pojo.EleInfo;
import com.zl.learning.xml.pojo.Translate;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class TestJaxb {
    private JaxbUtil jaxbUtil = JaxbUtil.getInstance();

    @Test
    public void test4() {
        EleInfo eleInfo = new EleInfo();
        eleInfo.setCode("0");
        eleInfo.setValue("男");
        EleInfo eleInfo2 = new EleInfo();
        eleInfo2.setCode("1");
        eleInfo2.setValue("女");
        Translate translate = new Translate();
        List<EleInfo> eleInfos = new ArrayList<>();
        eleInfos.add(eleInfo);
        eleInfos.add(eleInfo2);
        Dic dic = new Dic();
        dic.setName("DIC_SEX");
        dic.setEleInfos(eleInfos);

        EleInfo eleInfo3 = new EleInfo();
        eleInfo3.setCode("0");
        eleInfo3.setValue("中国");
        EleInfo eleInfo4 = new EleInfo();
        eleInfo4.setCode("1");
        eleInfo4.setValue("美国");
        List<EleInfo> eleInfos2 = new ArrayList<>();
        eleInfos2.add(eleInfo3);
        eleInfos2.add(eleInfo4);
        Dic dic2 = new Dic();
        dic2.setName("DIC_COUNTRY");
        dic2.setEleInfos(eleInfos2);


        List<Dic> dics = new ArrayList<>();
        dics.add(dic);
        dics.add(dic2);
        translate.setDics(dics);

        Gson gson = new Gson();
        String tran = gson.toJson(translate);
        System.out.println(tran);
        String val = jaxbUtil.convertToXml(translate);
        System.out.println(val);
    }
}
